#!/bin/sh
# peasywifi rc.network 'stop' implementation missing from /etc/pwf/rc.network
set -x; exec >&2 #DEBUG
. /etc/pwf/pwf.conf
CONNECTEDLINKS=$(ip -o address show | grep 'inet' | cut -f 2 -d ' ')
if echo $CONNECTEDLINKS | grep -qw "$INTERFACE"; then
	CURRENTIPS=$(ip addr show | grep $INTERFACE | grep inet | awk '{print $2}') #in case there are several
	for I in $CURRENTIPS; do ip addr del $I dev $INTERFACE; done
	ifconfig $INTERFACE down
	
	killall wpa_supplicant
	rm -f /var/run/wpa_supplicant/*
	killall udhcpc
else #disconnect other (wired) interfaces
	ETHLINKS=$(ip -o link show | grep 'link/ether' | cut -f 2 -d ' ' | tr -d :)
	for INTERFACE in $ETHLINKS;do
		ifconfig $INTERFACE down
	done
fi
killall peasywifi_tray
chmod -x /root/Startup/peasywifi_tray
